home *** CD-ROM | disk | FTP | other *** search
- Path: news.primenet.com!bjg
- From: Brad Grossman <bjg@primenet.com>
- Newsgroups: comp.lang.c++
- Subject: Help needed with class for filename data
- Date: 21 Mar 1996 00:21:01 -0700
- Organization: Primenet (602)395-1010
- Sender: root@primenet.com
- Message-ID: <4ir00t$33m@nnrp1.news.primenet.com>
- X-Posted-By: bjg@usr1.primenet.com
-
- ....I'm trying to make a class that will take a sorted directory of a
- directory, and then use the info for a few things. When I try to use the
- class I'm using for storing the file info in a direct sorted array of
- either my design or that in Borland C++ 3.0 container classes or indirect
- ones of my design (it does work with indirect container classes, but
- since they can't be expanded, they are of little use) the machine
- crashes. I have given up on figuring out the problem on my own, and need
- help...I cannot see what is going wrong. Here is the heart of the class:
-
- class FileData: public Date, public Time
- {
- protected:
-
- char *fileName;
- char *ext;
- Date fileDate;
- Time fileTime;
- long fileSize;
-
- };
-
- FileData::FileData() :
- fileDate(1,1,80),
- fileTime()
-
- {
- fileName="";
- ext="";
- fileSize=0;
- };
-
- FileData::~FileData()
- {
- delete fileName;
- delete ext;
- }
-
- FileData::FileData( ffblk& blk ) :
- fileDate( (blk.ff_fdate >> 5) & 0x000F,
- blk.ff_fdate & 0x0001F,
- (blk.ff_fdate >> 9) + 80 ),
- fileSize( blk.ff_fsize ),
- fileTime( blk.ff_ftime >> 11,
- (blk.ff_ftime >> 5) & 0x3F,
- blk.ff_ftime & 0x1F )
- {
- int ex = 0;
- fileName = new char[8];
- ext = new char[3];
-
-
- for (int i=0; i < 12; i++) {
-
- if (blk.ff_name[i] == '.') {
- fileName[i] = '\0';
- ex = i+1;
- continue;
- };
-
- if ((blk.ff_name[i] == ' ' || blk.ff_name[i] == '\0') && ex ) {
- ext[i-ex]='\0';
- break;
- };
-
-
- if (!ex ) {
- fileName[i] = blk.ff_name[i];
- };
-
- if (ex) {
- ext[i-ex] = blk.ff_name[i];
- };
-
- };
- fileName[8]='\0';
- ext[3]='\0';
-
- };
-
- FileData& FileData::operator=(const FileData &f)
- {
- delete fileName;
- delete ext;
- fileName = new char[8];
- ext = new char[3];
- strcpy(fileName,f.fileName);
- strcpy(ext,f.ext);
- fileSize=f.fileSize;
- fileDate=f.fileDate;
- fileTime=f.fileTime;
- if (this==&f) return *this;
- };
-
- FileData::FileData(const FileData &f)
- {
- strcpy(fileName,f.fileName);
- strcpy(ext,f.ext);
- fileSize=f.fileSize;
- fileDate=f.fileDate;
- fileTime=f.fileTime;
- };
-
- The problem is somewhere in here...some problem in memory allocation
- probably. Please mail me if you can figure out what is going wrong
- here...or if you have a working framework for this sort of thing...
-
-
- --
- Brad Grossman "Energy derives from both the plus and negative"
- Metallica, Eye of the Beholder
-